import sys
sys.path.append("/home/sivan/0_0/projects/gitee/others")
from latex2sympy.process_latex import process_sympy
from sympy import latex, N
from pydantic import BaseModel

class Calc_model(BaseModel):
    expr: str

def calc(data):
    expr = data.expr
    result = {'latex': '', 'text': '', 'float': '', 'error': ''}
    try: lexpr = process_sympy(expr)
    except:
        result['error'] = "错误的表达式: " + str(expr)
        return result
    ansr = lexpr.doit()
    result['latex'] = latex(ansr)
    result['text'] = str(ansr)
    result['float'] = str(N(ansr, 6))
    return result

